home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
newsgroups
/
misc.20031118-20041115
/
000289_thucdat@hotmail.com_Mon May 10 09:29:55 2004.msg
< prev
next >
Wrap
Internet Message Format
|
2004-11-14
|
5KB
Path: newsmaster.cc.columbia.edu!panix!news.maxwell.syr.edu!postnews1.google.com!not-for-mail
From: thucdat@hotmail.com (Dat Nguyen)
Newsgroups: comp.protocols.kermit.misc
Subject: Logic Programming in C-Kermit
Date: 9 May 2004 16:59:18 -0700
Organization: http://groups.google.com
Lines: 143
Message-ID: <6b1f50ac.0405091559.58c4b822@posting.google.com>
NNTP-Posting-Host: 24.118.27.71
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1084147158 30628 127.0.0.1 (9 May 2004 23:59:18 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 9 May 2004 23:59:18 +0000 (UTC)
Xref: newsmaster.cc.columbia.edu comp.protocols.kermit.misc:15010
After a few rounds of Object-Oriented Programming in C-Kermit, I hope you've
seen that C-Kermit can do OOP to solve some tough problems. I am about to embark
on Patterns, an advanced software subject, when I tumble on the following puzzle
in a Prolog book (Prolog and Lisp are considered as the two big tools to
research artificial intelligence):
===============================================================================
Implement an inference engine that can handle symmetric 2-place predicates
(those whose arguments can be interchanged) without looping. Put the functor
symmetric in front of each fact that is to have the symmetric property, and let
symmetric be a prefix operator. For example:
symmetric married(john,mary).
symmetric married(melody,michael).
?- prove(married(mary,john)).
yes
?- prove(married(john,mary)).
yes
?- prove(married(michael,Who)).
Who = melody
?- prove(married(abc,xyz)).
no
===============================================================================
Following is my implementation in C-Kermit:
###############################################################################
define symmetric {
if > \find({\%2},\m(\%1.contain)) 0 {
echo Relation \%1 \%2 already defined
return 1
}
local \&z[]
void \fsplit(\%2,&z,{,})
if > \farraylook(who,&z) -1 {
echo Cannot relate with who
return 0
}
_define \%1 1
_asg \%1.contain \m(\%1.contain)|\%2|
return 1
}
define prove {
if not define \m(\%1) {
echo Relation \%1 does not exist
return 0
}
local \%n \&w[] \&z[]
asg \%n \fsplit(\m(\%1.contain),&w,|)
void \fsplit(\%2,&z,{,})
if > \farraylook(\%2,&w) -1 {
echo Yes
return 1
} else if > \farraylook({\&z[2],\&z[1]},&w) -1 {
echo Yes
return 1
} else if > \find(\&z[2],who) 0 {
local \%f \%i
asg \%f 0
for \%i 1 \%n 1 {
if > \find(\&z[1],\&w[\%i]) 0 {
echo Who = \freplace(\freplace(\&w[\%i],\&z[1]),{,})
asg \%f 1
}
}
return \%f
} else {
echo No
return 0
}
}
###############################################################################
# In a typical soccer tournament, the following matches are usual:
symmetric playsoccer Brazil,Italy
symmetric playsoccer Germany,Italy
symmetric playsoccer England,Brazil
symmetric playsoccer England,Germany
symmetric playsoccer Italy,Germany
symmetric playsoccer Holland,Germany
symmetric playsoccer France,Italy
symmetric playsoccer England,France
# In a chess tournament, the following encounters are possible:
symmetric playchess Karpov,Kasparov
symmetric playchess Leko,Kasparov
symmetric playchess Leko,Kramnik
symmetric playchess Karpov,Kramnik
symmetric playchess Annand,Kramnik
symmetric playchess Leko,Karpov
symmetric playchess Ponomariov,Karpov
symmetric playchess Polga,Karpov
symmetric playchess Leko,Polga
# In a party, the following pairs would happen:
symmetric danceWith Jane,Robert
symmetric danceWith Jennifer,Mark
symmetric danceWith Mary,John
symmetric danceWith Mary,Robert
symmetric danceWith Suzie,George
symmetric danceWith Kevin,Carol
symmetric danceWith Mark,Carol
# All relations playsoccer, playchess, and danceWith can live in the same
environment.
# To see if France play Germany:
prove playsoccer France,Germany
# To see which teams Brazil plays:
prove playsoccer Brazil,Who
# To see if Brazil plays Belgium:
prove playsoccer Brazil,Belgium
# To see if Mark kissed any girl in the party:
prove kiss Mark,Who
# You'll find the relation kiss hasn't been defined, that is nobody has kissed
anybody. Playboy is a rare animal.
As you see, everything, be it Expert system or AI, is only the fakes happening
on the surface. Below the surface is just the handling of bits and bytes.
With this, I've just entered the world of logic programming in C-Kermit. Stay
tuned, many exciting things are going to happen here.
The script is also found at:
ftp://kermit.columbia.edu/kermit/scripts/ckermit/symmetric
Dat